package falling 
{
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class Birds extends SelectableObject
	{
		[Embed (source = "../../data/falling/2_birds.png")] private var img_birds:Class;
		public function Birds(x:int, y:int) 
		{
			super(x, y, img_birds);
			selectable = false;
			alpha = 0;
			baseScale = 0.8;
		}
		
		override public function update():void 
		{
			super.update();
			var cloud:Cloud = (FlxG.state as FallingState2).cloud;
			if (!overlapsPoint(new FlxPoint(cloud.x + cloud.width / 2, cloud.y + cloud.height / 2)))
			{
				velocity.x = 30;
				alpha += FlxG.elapsed;
			}
			else
			{
				velocity.x = 0;
				alpha -= FlxG.elapsed;
			}
			if (alpha >= 1)
			{
				selectable = true;
			}
			
			var player:FlxSprite = (FlxG.state as FallingState2).player;
			if (selectedValue > 0.5)
			{
				if (player.angle < 160)
				{
					player.angularVelocity = 45;
				}
				else
				{
					player.angularVelocity = 0;
				}
			}
			if (player.angle >= 160)
			{
				player.angularVelocity = 0;
				player.acceleration.y = -selectedValue * 50;
				player.drag.y = 30;
				(FlxG.state as FallingState2).text3.clearingToWord = 999;
			}
		}
		
	}

}